/*************************************************************************************
* qTESLA: an efficient post-quantum signature scheme based on the R-LWE problem
*
* Abstract: script to generate the precomputed CDT table
**************************************************************************************/


function rho2(k)
    return 1/2^(k^2);
end function;

z := 11;     // <- Maximum for 64-bit precision (use z=11 for NIST's category 1, z=13 for NIST's category 3)
s := 0;
for k in [0..z] do
    s +:= rho2(k);
end for;
num := Numerator(s);
assert Denominator(s) eq 2^(z^2);
den := 2^(z^2);
s := 0;
for k in [0..z] do
    prev := s;
    s +:= rho2(k);
    r := Numerator(den*s);
    v := IntegerToString(r, 16); 
	v := "0"^(64 - #v) cat v;
    k, ":", v[1..16], v[17..32], v[33..48], v[49..64],  ":", 1.0*(r/num);
end for;



        	
Table z := 11;

0  : 0200000000000000 0000000000000000 : 0.63919475222583943592733985711
1  : 0300000000000000 0000000000000000 : 0.95879212833875915389100978567
2  : 0320000000000000 0000000000000000 : 0.99874180035287411863646852674
3  : 0321000000000000 0000000000000000 : 0.99999022760331521128476411240
4  : 0321020000000000 0000000000000000 : 0.99999998094120928232107892166
5  : 0321020100000000 0000000000000000 : 0.99999999999069735667857172402
6  : 0321020100200000 0000000000000000 : 0.99999999999999886452737909356
7  : 0321020100200100 0000000000000000 : 0.99999999999999999996534891868
8  : 0321020100200100 0200000000000000 : 0.99999999999999999999999973562
9  : 0321020100200100 0200010000000000 : 1.0000000000000000000000000000
10 : 0321020100200100 0200010000200000 : 1.0000000000000000000000000000
11 : 0321020100200100 0200010000200001 : 1.0000000000000000000000000000




Table z := 13;

0 : 0000020000000000 0000000000000000 0000000000000000 : 0.63919475222583943592733985711
1 : 0000030000000000 0000000000000000 0000000000000000 : 0.95879212833875915389100978567
2 : 0000032000000000 0000000000000000 0000000000000000 : 0.99874180035287411863646852674
3 : 0000032100000000 0000000000000000 0000000000000000 : 0.99999022760331521128476411240
4 : 0000032102000000 0000000000000000 0000000000000000 : 0.99999998094120928232107892166
5 : 0000032102010000 0000000000000000 0000000000000000 : 0.99999999999069735667857172402
6 : 0000032102010020 0000000000000000 0000000000000000 : 0.99999999999999886452737909356
7 : 0000032102010020 0100000000000000 0000000000000000 : 0.99999999999999999996534891869
8 : 0000032102010020 0100020000000000 0000000000000000 : 0.99999999999999999999999973562
9 : 0000032102010020 0100020001000000 0000000000000000 : 1.0000000000000000000000000000
10 : 0000032102010020 0100020001000020 0000000000000000 : 1.0000000000000000000000000000
11 : 0000032102010020 0100020001000020 0001000000000000 : 1.0000000000000000000000000000
12 : 0000032102010020 0100020001000020 0001000002000000 : 1.0000000000000000000000000000
13 : 0000032102010020 0100020001000020 0001000002000001 : 1.0000000000000000000000000000